Skip to content

@W-21741005: NEW - Implement Strategy Pattern for multi-engine custom rule creation#441

Open
aruntyagiTutu wants to merge 9 commits into
mainfrom
feat/create-rule-regex-engine-support
Open

@W-21741005: NEW - Implement Strategy Pattern for multi-engine custom rule creation#441
aruntyagiTutu wants to merge 9 commits into
mainfrom
feat/create-rule-regex-engine-support

Conversation

@aruntyagiTutu
Copy link
Copy Markdown
Contributor

@aruntyagiTutu aruntyagiTutu commented Apr 14, 2026

This is to confirm that this is working in AFV.

@W-21741005@

  • Created strategy pattern infrastructure for extensible rule creation
  • Added IRuleCreationStrategy interface defining strategy contract
  • Implemented XPathRuleStrategy for PMD/XPath rules
  • Implemented RegexRuleStrategy for regex pattern rules
  • Created RuleCreationStrategyFactory for engine-based strategy selection
  • Refactored create_custom_rule tool to use strategy pattern
  • Tool now supports both engine: "pmd" and engine: "regex"
  • Added CreateRegexCustomRuleActionImpl for regex rule creation
  • Created temporary create_regex_rule tool for testing (to be deleted)
  • Updated provider to use RuleCreationStrategyFactory

Benefits:

  • Single entry point for multiple engines
  • Easy to extend with new engines
  • Engine-specific logic isolated in strategies
  • Maintains backward compatibility with existing PMD functionality

Regex rules support:

  • Inline YAML rules in code-analyzer.yml
  • Required: regex, violationMessage, tags, severity
  • Optional: fileExtensions, regexIgnore, includeMetadata
  • Validates regex format, severity range, file extensions

Note: unit tests and testing is pending after stretegy pattern and need to delete create-regex-rule tool, that was created only for testing puprpose.

- Created strategy pattern infrastructure for extensible rule creation
- Added IRuleCreationStrategy interface defining strategy contract
- Implemented XPathRuleStrategy for PMD/XPath rules
- Implemented RegexRuleStrategy for regex pattern rules
- Created RuleCreationStrategyFactory for engine-based strategy selection
- Refactored create_custom_rule tool to use strategy pattern
- Tool now supports both engine: "pmd" and engine: "regex"
- Added CreateRegexCustomRuleActionImpl for regex rule creation
- Created temporary create_regex_rule tool for testing (to be deleted)
- Updated provider to use RuleCreationStrategyFactory

Benefits:
- Single entry point for multiple engines
- Easy to extend with new engines
- Engine-specific logic isolated in strategies
- Maintains backward compatibility with existing PMD functionality

Regex rules support:
- Inline YAML rules in code-analyzer.yml
- Required: regex, violationMessage, tags, severity
- Optional: fileExtensions, regexIgnore, includeMetadata
- Validates regex format, severity range, file extensions
@aruntyagiTutu aruntyagiTutu requested a review from a team as a code owner April 14, 2026 10:10
@aruntyagiTutu aruntyagiTutu changed the title @W-21741005@ - NEW: Implement Strategy Pattern for multi-engine custom rule creation @W-21741005: NEW - Implement Strategy Pattern for multi-engine custom rule creation Apr 14, 2026
- Refactored create_custom_rule.test.ts to use strategy mocks
- Updated provider.test.ts to expect 7 tools (added temporary create_regex_rule)
- All 228 tests passing
- Coverage: 89.05% statements, 76.76% branches
…ests

- Commented out create_regex_rule tool registration in provider
- Tool code kept in codebase for reference only
- Users can test regex rule creation via create_custom_rule with engine: 'regex'
- Updated provider test to expect 6 tools instead of 7
- All 228 tests passing
- E2E tests should now pass (9 tools expected)
- Added RegexRuleStrategy.test.ts with 26 tests
- Added XPathRuleStrategy.test.ts with 20 tests
- Added RuleCreationStrategyFactory.test.ts with 13 tests
- Total: 59 new tests added
- All 287 tests passing

Coverage improvements:
- RegexRuleStrategy: 8.69% → 100%
- XPathRuleStrategy: 11.11% → 100%
- RuleCreationStrategyFactory: 38.46% → 100%
- Overall: 89.05% → 97.37%

Test coverage includes:
- Validation logic for all required/optional fields
- Error handling for invalid inputs
- Execute functionality for rule creation
- File system operations (config creation/updates)
- Factory pattern (strategy selection and registration)
- Edge cases (case sensitivity, whitespace handling)
- Restored create_regex_rule.ts that was accidentally deleted
- File kept for manual testing reference only (not registered in provider)
- Increased 'should enable 1 tool and a toolset' test timeout from 60s to 90s
- Added connection timeout with Promise.race to fail fast on server issues
- Connection timeout set to 90s for Windows compatibility

This addresses E2E test failures on Windows runners where connection
establishment takes longer than on Linux/macOS.
@aruntyagiTutu aruntyagiTutu requested a review from a team as a code owner April 16, 2026 13:06
"For Apex and Visualforce, use tool 'get_ast_nodes_to_generate_xpath' to generate the XPath."
);
} else {
errors.push("xpath is required for PMD engine. Provide a valid XPath expression.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is LLM going to read these error messages and act on the basis of that?

Comment thread packages/mcp-provider-code-analyzer/src/tools/create_custom_rule.ts
Copy link
Copy Markdown

@ZLeventer ZLeventer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Strategy Pattern refactor for multi-engine rule creation is a meaningful architectural improvement. Having a pluggable engine interface makes it straightforward to add new analysis engines without modifying existing code paths.

From a user perspective, the key benefit here is extensibility — custom rule engines can be dropped in without touching the core MCP tool registration. This matters for teams that have proprietary static analysis rules they want to integrate alongside the built-in engines.

The workingDirectory parameter addition in #439 (which this builds on) is also important — without it, the MCP server assumes CWD which breaks in many IDE integration scenarios where the MCP server's CWD doesn't match the project being analyzed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants